function createRequestObject() {
  if (typeof XMLHttpRequest === 'undefined') {
    XMLHttpRequest = function() {
      try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
        catch(e) {}
      try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
        catch(e) {}
      try { return new ActiveXObject("Msxml2.XMLHTTP"); }
        catch(e) {}
      try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch(e) {}
      throw new Error("This browser does not support XMLHttpRequest.");
    };
  }
  return new XMLHttpRequest();
}

function processReqChange(req, eventData, eventError, options)
{
  try {
    if (req.readyState == 4) {
      req.onreadystatechange = null;
      if (req.status == 200) {
          if (options && options['asHTML'] == true) {
            var container = document.createElement('div');
            container.innerHTML = req.responseText;
            eventData(container);
          }
          else if (options && options['asXML'] == true)
            if (typeof(req.responseXML) != 'undefined')
              eventData(req.responseXML);
            else
              eventError('Not XML in data.');
          else
            eventData(req.responseText);
      } else {
          eventError(req.statusText);
      }
    }
  }
  catch( e ) {
    eventError('Fatal error.');
  }
}

function httpRequest(url, data, eventData, eventError, options)
{
  var req = createRequestObject();
  req.onreadystatechange = function (){processReqChange(req, eventData, eventError, options)};
  req.open("POST", url, true);
  req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
  req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  req.send(data);
}